package com.yanqu.road.server.logic.bag;

import com.yanqu.road.entity.bag.UseGoodsResult;
import com.yanqu.road.entity.config.goods.GoodsInfo;
import com.yanqu.road.entity.config.skin.SkinInfo;
import com.yanqu.road.entity.enums.eSkinType;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.patrons.PatronsModule;
import com.yanqu.road.server.gameplayer.module.player.BeautyModule;
import com.yanqu.road.server.gameplayer.module.player.EstateWarModule;
import com.yanqu.road.server.gameplayer.module.skin.SkinModule;
import com.yanqu.road.server.manger.config.GoodsMgr;
import com.yanqu.road.server.manger.config.SkinMgr;
import com.yanqu.road.server.manger.manor.ManorMgr;
import com.yanqu.road.server.protocol.GameErrorCode;

/**
 * @Author wpj
 * @Date 2020/9/1
 */
public class UseSkin extends BaseUseGoods {
    private int skinType;

    public UseSkin(GamePlayer player, GoodsInfo goodsInfo, long param) {
        super(player, goodsInfo, param);
    }

    @Override
    int checkUse(long count) {
        if (count != 1) {
            return GameErrorCode.E_SKIN_USE_NUM_ERROR;
        }
        SkinInfo skinInfo = SkinMgr.getSkinInfoMap().get(goodsInfo.getGoodsId());
        if (skinInfo == null) {
            int skinGoodId = GoodsMgr.getLTPMainRoleSkinGoodId(goodsInfo.getGoodsId());
            if (skinGoodId == 0) {
                return GameErrorCode.E_SKIN_TYPE_ERROR;
            }
            skinInfo = SkinMgr.getSkinInfoMap().get(skinGoodId);
            if (skinInfo.getType() != eSkinType.LTPMainRole.getValue()) {
                return GameErrorCode.E_SKIN_TYPE_ERROR;
            }
        } else {
            if (skinInfo.getType() == eSkinType.Beauty.getValue()) {
                if (player.getModule(BeautyModule.class).getUserBeauty(skinInfo.getBelongRole()) == null) {
                    return GameErrorCode.E_BEAUTY_NO_FOUND;

                }
            } else if (skinInfo.getType() == eSkinType.Patrons.getValue()) {
                if (player.getModule(PatronsModule.class).getUserPatrons(skinInfo.getBelongRole()) == null) {
                    return GameErrorCode.E_PATRONS_NO_FOUND;
                }
            } else if (skinInfo.getType() == eSkinType.MainRole.getValue()) {
                // 主角时装 无需处理
            } else if (skinInfo.getType() == eSkinType.ManorObject.getValue()) {
                if (!ManorMgr.objectUnLock(skinInfo.getBelongRole(), player)) {
                    return GameErrorCode.E_MANOR_OBJ_IS_LOCK;
                }
            } else if (skinInfo.getType() == eSkinType.EstateSkin.getValue()) {
                // 府邸皮肤
                if (skinInfo.getBelongRole() < 100) {
                    return GameErrorCode.E_SKIN_TYPE_ERROR;
                }
            }else if (skinInfo.getType() == eSkinType.BankSkin.getValue()) {
                // 钱庄皮肤 不知道要处理什么
            } else {
                return GameErrorCode.E_SKIN_TYPE_ERROR;
            }
        }
        skinType = skinInfo.getType();
        return 0;
    }

    @Override
    UseGoodsResult executeUse(long count) {
        if (skinType == eSkinType.LTPMainRole.getValue()) {
            player.getModule(SkinModule.class).useLTPMainRoleSkin(goodsInfo.getGoodsId());
        } else {
            player.getModule(SkinModule.class).useSkin(goodsInfo.getGoodsId());
        }
        return new UseGoodsResult();
    }
}
